package top.tangyh.lamp.care.mapper;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.lamp.care.entity.BHl7LisBar;
import org.springframework.stereotype.Repository;
import top.tangyh.lamp.care.vo.query.ListBarQueryVO;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 检验申请-条码打印完成数据
 * </p>
 *
 * @author zqb
 * @date 2024-08-02 16:04:08
 * @create [2024-08-02 16:04:08] [zqb] [代码生成器生成]
 */
@Repository
public interface BHl7LisBarMapper extends SuperMapper<BHl7LisBar> {

    default List<BHl7LisBar> selectLisBarByQuery(ListBarQueryVO queryVO) {
        String patientIdent = queryVO.getPatientIdent();
        String hospitalNumber = queryVO.getHospitalNumber();

        Long startTime = queryVO.getStartTime();
        Long endTime = queryVO.getEndTime();
        LambdaQueryWrapper<BHl7LisBar> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StrUtil.isNotBlank(patientIdent), BHl7LisBar::getPatientIdent, patientIdent)
                .eq(StrUtil.isNotBlank(hospitalNumber), BHl7LisBar::getHospitalNumber, hospitalNumber)
                .eq(BHl7LisBar::getIsCancel, 0).and(wapper -> {
//                    wapper.or(wapper1 -> {
//                        wapper1.and(wapper11 -> {
//                            wapper11.isNotNull(BHl7LisBar::getReportTime).ge(startTime != null, BHl7LisBar::getReportTime, DateUtil.formatDateTime(DateUtil.date(startTime)))
//                                    .le(endTime != null, BHl7LisBar::getReportTime, DateUtil.formatDateTime(DateUtil.date(endTime)));
//                        });
//                    });
                    wapper.or(wapper2 -> {
                        wapper2.and(wapper22 -> {
                            wapper22.isNull(BHl7LisBar::getReportTime).ge(startTime != null, BHl7LisBar::getBarTime, DateUtil.formatDateTime(DateUtil.date(startTime)))
                                    .le(endTime != null, BHl7LisBar::getBarTime, DateUtil.formatDateTime(DateUtil.date(endTime)));
                        });
                    });
                });
        return this.selectList(queryWrapper);
    }



}


